home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / pyshared / UpdateManager / DistUpgradeFetcher.py < prev    next >
Text File  |  2009-11-02  |  5KB  |  118 lines

  1. # DistUpgradeFetcher.py 
  2. #  
  3. #  Copyright (c) 2006 Canonical
  4. #  
  5. #  Author: Michael Vogt <michael.vogt@ubuntu.com>
  6. #  This program is free software; you can redistribute it and/or 
  7. #  modify it under the terms of the GNU General Public License as 
  8. #  published by the Free Software Foundation; either version 2 of the
  9. #  License, or (at your option) any later version.
  10. #  This program is distributed in the hope that it will be useful,
  11. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #  GNU General Public License for more details.
  14. #  You should have received a copy of the GNU General Public License
  15. #  along with this program; if not, write to the Free Software
  16. #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  17. #  USA
  18.  
  19. import pygtk
  20. pygtk.require('2.0')
  21. import gtk
  22.  
  23. from ReleaseNotesViewer import ReleaseNotesViewer
  24. from Core.utils import *
  25. from Core.DistUpgradeFetcherCore import DistUpgradeFetcherCore
  26. from gettext import gettext as _
  27. import urllib2
  28. import dbus
  29. import os
  30. import socket
  31.  
  32.  
  33. class DistUpgradeFetcherGtk(DistUpgradeFetcherCore):
  34.  
  35.     def __init__(self, new_dist, progress, parent):
  36.         DistUpgradeFetcherCore.__init__(self,new_dist,progress)
  37.         self.parent = parent
  38.         self.window_main = parent.window_main
  39.  
  40.     def error(self, summary, message):
  41.         return error(self.window_main, summary, message)
  42.  
  43.     def runDistUpgrader(self):
  44.         inhibit_sleep()
  45.         # now run it with sudo
  46.         if os.getuid() != 0:
  47.             os.execv("/usr/bin/gksu",["gksu",
  48.                                       "--desktop","/usr/share/applications/update-manager.desktop",
  49.                                       "--",
  50.                                       self.script]+self.run_options)
  51.         else:
  52.             os.execv(self.script,[self.script]+self.run_options)
  53.         # we shouldn't come to this point, but if we do, undo our
  54.         # inhibit sleep
  55.         allow_sleep()
  56.  
  57.     def showReleaseNotes(self):
  58.       # FIXME: care about i18n! (append -$lang or something)
  59.       if self.new_dist.releaseNotesURI != None:
  60.           uri = self._expandUri(self.new_dist.releaseNotesURI)
  61.           self.window_main.set_sensitive(False)
  62.           self.window_main.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
  63.           while gtk.events_pending():
  64.               gtk.main_iteration()
  65.  
  66.           # download/display the release notes
  67.           # FIXME: add some progress reporting here
  68.           res = gtk.RESPONSE_CANCEL
  69.           timeout = socket.getdefaulttimeout()
  70.           try:
  71.               socket.setdefaulttimeout(5)
  72.               release_notes = urllib2.urlopen(uri)
  73.               notes = release_notes.read()
  74.               textview_release_notes = ReleaseNotesViewer(notes)
  75.               textview_release_notes.show()
  76.               self.parent.scrolled_notes.add(textview_release_notes)
  77.               self.parent.dialog_release_notes.set_transient_for(self.window_main)
  78.               res = self.parent.dialog_release_notes.run()
  79.               self.parent.dialog_release_notes.hide()
  80.           except urllib2.HTTPError:
  81.               primary = "<span weight=\"bold\" size=\"larger\">%s</span>" % \
  82.                         _("Could not find the release notes")
  83.               secondary = _("The server may be overloaded. ")
  84.               dialog = gtk.MessageDialog(self.window_main,gtk.DIALOG_MODAL,
  85.                                          gtk.MESSAGE_ERROR,gtk.BUTTONS_CLOSE,"")
  86.               dialog.set_title("")
  87.               dialog.set_markup(primary);
  88.               dialog.format_secondary_text(secondary);
  89.               dialog.run()
  90.               dialog.destroy()
  91.           except IOError:
  92.               primary = "<span weight=\"bold\" size=\"larger\">%s</span>" % \
  93.                         _("Could not download the release notes")
  94.               secondary = _("Please check your internet connection.")
  95.               dialog = gtk.MessageDialog(self.window_main,gtk.DIALOG_MODAL,
  96.                                          gtk.MESSAGE_ERROR,gtk.BUTTONS_CLOSE,"")
  97.               dialog.set_title("")
  98.               dialog.set_markup(primary);
  99.               dialog.format_secondary_text(secondary);
  100.               dialog.run()
  101.               dialog.destroy()
  102.           socket.setdefaulttimeout(timeout)              
  103.           self.window_main.set_sensitive(True)
  104.           self.window_main.window.set_cursor(None)
  105.           # user clicked cancel
  106.           if res == gtk.RESPONSE_OK:
  107.               return True
  108.       return False
  109.  
  110. if __name__ == "__main__":
  111.     error(None, "summary","message")
  112.     d = DistUpgradeFetcherGtk(None,None)
  113.     print d.authenticate('/tmp/Release','/tmp/Release.gpg')
  114.  
  115.